#!/usr/bin/env bash
avs_uid=0
runFileName="$1.jar"
echo "删除原文件......"
rm -rf /usr/local/bin/${runFileName}
echo "移动${runFileName}......"
mv $1 /usr/local/bin
echo "进入运行目录....."
cd /usr/local/bin
echo "查找文件进程....."
# 查找文件进程
process=$1
avs_uid=$(ps -ef | grep ${process} | grep '.jar' | grep -v grep | awk '{print $2}')
echo "pid=${avs_uid}"
isRun="Y"
echo "${runFileName}：${avs_uid}"

if test ${avs_uid} = ""
then echo "avs_uid = ${avs_uid}"
read -p "进程ID为0，是否继续？(Y/N)" isRun
fi
if test ${isRun} = "N"
then exit -1
else
  echo "结束文件进程....."
  kill -9 ${avs_uid}
fi
echo "运行文件....."
nohup java -jar ${runFileName} --server.port=$2 &
#nohup java -jar $1 --server.port=$2 >/dev/null 2>&1 &
echo "==================================================="
echo "              run ${runFileName} in port $2 !"
echo "==================================================="
